﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StructureMap.Configuration.DSL;
using Core.IRepository;
using System.Configuration;
using Repositories;
using System.Data.Entity;
using StructureMap;
using StructureMap.Pipeline;
using Core.Domain;
using StructureMap.Graph;
using Core.Dtos;
using Core.IRepository.Admin;
using Repositories.Admin;
using CMS.Repositories;

namespace DI
{
    public class RepositoryRegistry : Registry
    {
        public RepositoryRegistry(ILifecycle lifecycle)
        {            
            For<AdminDbContext>().LifecycleIs(lifecycle);            

            Scan(x =>
            {
                x.Assembly("CMS.Repositories");
                x.Include(t => !t.IsAbstract && (t.Name.EndsWith("Repository") || t.Name.EndsWith("UnitOfWork")));
                x.WithDefaultConventions().OnAddedPluginTypes(c => c.LifecycleIs(lifecycle));
            });
            Scan(x =>
            {
                x.Assembly("Share.Enterprise");
                x.Include(t => !t.IsAbstract && (t.Name.EndsWith("Repository") || t.Name.EndsWith("UnitOfWork")));
                x.WithDefaultConventions().OnAddedPluginTypes(c => c.LifecycleIs(lifecycle));
            });            

            For(typeof(IQueryHelper<>)).LifecycleIs(lifecycle).Use(typeof(QueryHelper<>));
            For(typeof(IAdminRepository<,>)).LifecycleIs(lifecycle).Use(typeof(AdminRepository<,>));            
        }
    }
}
